define([
    'config',
    'ApiClient'
], function(config,ApiClient){
    function isEmptyObject(e) {
        var t;
        for (t in e)
            return !1;
        return !0;
    }
    var UploadFile = function(json_params,srolid, refunc){
        var param = new FormData();
        var uploadInput = json_params.files;//document.getElementById('fileupload-tools');
        if(uploadInput.value == "") {
            alert("上传文件不能空");
            return ;
        }
        //alert(uploadInput.files.length);
        for(var i = 0; i< uploadInput.files.length; i++){//v==value　为arr项，i==index　为arr索引
            param.append("fileArray",uploadInput.files[i]);   // 文件对象
        }
        if(isEmptyObject(json_params.params)){
            alert("传递的参数不能为空");
            return ;
        }
        for(var key in json_params.params){
            $('body').append(key+": "+json_params.params[key]+"<br/>");
            param.append(key, json_params.params[key]);
        } 
        //param.append('file', uploadInput.files[0]);
        ApiClient.postfile(config.webapiUrl + 'file',param, srolid).then(function (resValue) {
            refunc(resValue);
        });
    };
    return UploadFile;
});